package lb.io.object;

import lb.io.api.system.v1.Lblet;
import lb.io.apimachinery.pkg.apis.meta.v1.ObjectMeta;
import lb.io.apimachinery.pkg.apis.meta.v1.OwnerComponent;
import lb.io.apimachinery.pkg.apis.meta.v1.OwnerReference;
import lb.io.apimachinery.runtime.scheme.GroupVersionKind;
import lb.io.apis.meta.v1.Namespace;
import lb.io.utils.Strings;

public class Tool {
    public static ObjectMeta.Builder objectMetaBuilder(Namespace ns, String name) {
        return ObjectMeta.newBuilder()
                .setNamespace(ns.toString())
                .setName(name)
                .setUid(Strings.UUID())
                .setGenerateName(Strings.RandomName(6));
    }

    public static OwnerReference buildOwnerReference(GroupVersionKind gvk, ObjectMeta meta) {
        return OwnerReference.newBuilder()
                .setApiVersion(gvk.GroupKind().toString())
                .setKind(gvk.getKind())
                .setName(meta.getName())
                .setUid(meta.getUid())
                .setController(true)
                .setBlockOwnerDeletion(true)
                .build();
    }

    public static OwnerComponent buildOwnerComponent(Lblet lblet) {
        return OwnerComponent.newBuilder()
                .setMark("lblet")
                .setName(lblet.getMetadata().getName())
                .setUid(lblet.getMetadata().getUid())
                .build();
    }
}
